package com.ruoyi.material.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.material.domain.MateriaPurchaseRecord;
import com.ruoyi.material.service.IMateriaPurchaseRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 材料采购记录Controller
 * 
 * @author liboyu
 * @date 2024-06-16
 */
@RestController
@RequestMapping("/material/materialPurchase")
public class MateriaPurchaseRecordController extends BaseController
{
    @Autowired
    private IMateriaPurchaseRecordService materiaPurchaseRecordService;

    /**
     * 查询材料采购记录列表
     */
    @PreAuthorize("@ss.hasPermi('material:materialPurchase:list')")
    @GetMapping("/list")
    public TableDataInfo list(MateriaPurchaseRecord materiaPurchaseRecord)
    {

        startPage();
        List<MateriaPurchaseRecord> list = materiaPurchaseRecordService.selectMateriaPurchaseRecordList(materiaPurchaseRecord);
        return getDataTable(list);
    }

    /**
     * 导出材料采购记录列表
     */
    @PreAuthorize("@ss.hasPermi('material:materialPurchase:export')")
    @Log(title = "材料采购记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MateriaPurchaseRecord materiaPurchaseRecord)
    {
        List<MateriaPurchaseRecord> list = materiaPurchaseRecordService.selectMateriaPurchaseRecordList(materiaPurchaseRecord);
        ExcelUtil<MateriaPurchaseRecord> util = new ExcelUtil<MateriaPurchaseRecord>(MateriaPurchaseRecord.class);
        util.exportExcel(response, list, "材料采购记录数据");
    }

    /**
     * 获取材料采购记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('material:materialPurchase:query')")
    @GetMapping(value = "/{purchaseRecordId}")
    public AjaxResult getInfo(@PathVariable("purchaseRecordId") Long purchaseRecordId)
    {
        return success(materiaPurchaseRecordService.selectMateriaPurchaseRecordByPurchaseRecordId(purchaseRecordId));
    }

    /**
     * 新增材料采购记录
     */
    @PreAuthorize("@ss.hasPermi('material:materialPurchase:add')")
    @Log(title = "材料采购记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody MateriaPurchaseRecord materiaPurchaseRecord)
    {
        return toAjax(materiaPurchaseRecordService.insertMateriaPurchaseRecord(materiaPurchaseRecord));
    }

    /**
     * 修改材料采购记录
     */
    @PreAuthorize("@ss.hasPermi('material:materialPurchase:edit')")
    @Log(title = "材料采购记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody MateriaPurchaseRecord materiaPurchaseRecord)
    {
        return toAjax(materiaPurchaseRecordService.updateMateriaPurchaseRecord(materiaPurchaseRecord));
    }

    /**
     * 删除材料采购记录
     */
    @PreAuthorize("@ss.hasPermi('material:materialPurchase:remove')")
    @Log(title = "材料采购记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{purchaseRecordIds}")
    public AjaxResult remove(@PathVariable Long[] purchaseRecordIds)
    {
        return toAjax(materiaPurchaseRecordService.deleteMateriaPurchaseRecordByPurchaseRecordIds(purchaseRecordIds));
    }
}
